﻿@{
    Layout = "~/Areas/Admin/Views/Shared/_LayoutAdmin.cshtml";
}
<div style=" padding:0px 5px 0px 5px; " id="index_ArticleDataList">

    <div class="layui-row layui-col-space10">
        <div class="layui-col-md2">
            <div class="grid-demo grid-demo-bg1">
                <div class="layui-card">
                    <div class="layui-card-header">文章分类</div>
                    <div class="layui-card-body">
                        <ul id="article_articleTypeLeftTree"></ul>
                    </div>
                </div>
                @*<blockquote class="layui-elem-quote layui-quote-nm">
                        <ul id="articleTypeLeftTree"></ul>
                    </blockquote>*@
            </div>
        </div>
        <div class="layui-col-md10">
            <div class="layui-card">
                <div class="layui-card-body" style="padding: 10px 8px;">
                    <div class="dataGrid_Toolbar">
                        <form class="layui-form" action="">
                            <div class="layui-form-item fs-mb-0">
                                <div class="layui-inline" style="float: left;">
                                    <div class="layui-input-inline" style="width: auto;">
                                        <button class="layui-btn layui-btn-normal layui-btn-sm" type="button" data-type="add"><i class="layui-icon">&#xe61f;</i>新增</button>
                                        <button class="layui-btn layui-btn-normal layui-btn-sm" type="button" data-type="update"><i class="layui-icon">&#xe642;</i>修改</button>
                                        <button class="layui-btn layui-btn-normal layui-btn-sm" type="button" data-type="delete"><i class="layui-icon">&#xe640;</i>删除</button>
                                        <button class="layui-btn layui-btn-normal layui-btn-sm" type="button" data-type="export"><i class="layui-icon">&#xe630;</i>导出</button>
                                    </div>
                                </div>

                                <div class="layui-inline" style="float: right;">
                                    <div class="layui-input-inline" style="width: auto;">
                                        <input class="layui-input fs-search-txt" name="id" id="search_txt" placeholder="标题/内容" autocomplete="off">
                                    </div>
                                    <div class="layui-input-inline" style="width: auto;">
                                        <button class="layui-btn layui-btn-sm" type="button" data-type="reload"><i class="layui-icon">&#xe615;</i>搜索</button>
                                    </div>
                                </div>
                            </div>
                        </form>
                    </div>

                    <table class="layui-hide" id="ArticleDataList" lay-filter="ArticleDataList"></table>
                    <script type="text/html" id="barDemo">
                        <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
                        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
                    </script>

                    <script type="text/html" id="ArticleEdit">
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    var index_ArticleDataList = $("#index_ArticleDataList")
    var bodyheight = 0;
    var treeid = "";
    $(function () {
        bodyheight = $(window).height();// document.body.scrollHeight;
    });

    layui.use(['form', 'table', 'jquery', 'tree'], function () {
        var table = layui.table;
        var form = layui.form
        var $ = layui.$;
        bodyheight = $(window).height();
        var gridview = freejs.dataGrid(table, form, {
            //freejs封装参数
            controller: "/Admin/Article",
            pageElem: index_ArticleDataList,
            elem: '#ArticleDataList',
            formElem: "ArticleEdit",
            formArea: ['1100px', '660px'],
            tableOptions: {
                //table固定参数
                where: function () {
                    var seniorQueryJson = {};
                    if (treeid != "") {
                        seniorQueryJson.TypeID = treeid;
                    }
                    seniorQueryJson = JSON.stringify(seniorQueryJson);
                    var query = { searchContent: $("input[type=search_txt]", index_ArticleDataList).val(), seniorQueryJson: seniorQueryJson };
                    return query;
                },
                cols: [[
                    { checkbox: true, fixed: true }
                    , { field: 'Id', title: 'Id', width: 80, fixed: 'left', unresize: true, sort: true }
                    , { field: 'Title', title: '标题', edit: 'text' }
                    , { field: 'Status', title: '状态', width: 80, edit: 'text', sort: true }
                    , { field: 'WatchCount', title: '阅读量市', width: 100 }
                    , { field: 'StarCount', title: '获赞数', width: 100 }
                    , { field: 'CreateDt', title: '创建时间', width: 160, sort: true }
                    , { field: 'UpdateDt', title: '修改时间', width: 160 }
                    , { fixed: 'right', title: '操作', toolbar: '#barDemo', width: 150 }
                ]],
                page: true,
                height: bodyheight - 212,
            },
            editBefore: function () {
                form.on('switch(switchTest)', function (data) {
                    if (this.checked) {
                        $("#OriginUrlArea").hide();
                        $("#DocContentArea").show();
                    }
                    else {
                        $("#OriginUrlArea").show();
                        $("#DocContentArea").hide();

                    }
                });
            },
            submitBefore: function (data) {
                data.field.OriginType = data.field.OriginType == "on" ? 1 : 0;
                return data;
            }
        });

        
        var treeData =  @Html.Raw(Html.ToJson(ViewBag.ArticleTreeDatas as List<FsCms.Entity.ArticleTypeTreeNode>));
        layui.tree({
            elem: '#article_articleTypeLeftTree', //传入元素选择器
            nodes: treeData,
            click: function (node) {
                treeid = node.id;
                gridview.reload();
                console.log(node) //node即为当前点击的节点数据
            }
        });

    });
</script>
